/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.control.command.media
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.commands.SequenceCommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import multimedia.control.business.MediaDelegate;
	import multimedia.control.event.media.GetMediaEvent;
	import multimedia.control.event.media.GetUserMediaEvent;
	import multimedia.control.event.media.SaveVideoEvent;
	import multimedia.model.LoginModel;
	import multimedia.model.vo.MediaVO;
	import multimedia.view.author;
	
	import mx.rpc.IResponder;

	public class SaveVideoCommand extends SequenceCommand implements ICommand, IResponder
	{
		
		private var event:SaveVideoEvent;
		
		override public function execute(event:CairngormEvent):void
		{
			var e:SaveVideoEvent = event as SaveVideoEvent;
			this.event = e;
			this.nextEvent = e.nextEvent;
			var service:MediaDelegate = new MediaDelegate(this);
			service.saveVideo(e.video, e.user);
		}
		
		public function result(data:Object):void
		{
			if(data.result)
			{
				new GetUserMediaEvent(LoginModel.getInstance().user).dispatch();
				(event.author as author).clearInput();
				new GetMediaEvent().dispatch();
				new GetMediaEvent(true).dispatch();
				executeNextCommand();
			}
		}
		
		public function fault(info:Object):void
		{
		}
		
	}
}